<template>

  <div>

    <el-form  :model="form" label-width="80px">
      <el-form-item label="菜单ID">
        <el-input v-model="form.menuId" readonly></el-input>
      </el-form-item>

      <el-form-item label="菜单名称">
        <el-input v-model="form.menuName"></el-input>
      </el-form-item>

      <el-form-item label="url">
        <el-input v-model="form.url"></el-input>
      </el-form-item>
      <el-form-item label="上级菜单">

        <el-select v-model="form.parentId" placeholder="请选择">
          <el-option
            v-for="item in menus"
            :key="item.menuId"
            :label="item.menuName"
            :value="item.menuId">
          </el-option>
        </el-select>




      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="save()">保存</el-button>

      </el-form-item>
    </el-form>



  </div>

</template>

<script>
import {getForm,save,update,getMenus} from "@/api/sys/menu";


export default{
  name:'MenuEdit',
  props:["id",'parentId'],
  data(){
    return {
      form:{
        menuId:'',
        menuName:'',
        url:'',
        parentId:null,
      },
      menus:[


      ]
    }
  },
  created() {
    //查询所有的菜单列表
    this.getMenus();

    this.form.parentId = this.parentId;

    if(this.id){
      this.getForm();
    }
  },
  methods:{
    getForm(){
      getForm(this.id).then((form) =>{
        this.form = form;
      }).catch((e)=>{
        console.log("失败的情况",e)
      });
    },

    save(){
      let promise  =  null;

      // delete  this.form.createtime;

      if(this.id) {
        promise = update( this.form);
      }else{
        promise = save( this.form);
      }
      // form /
      promise.then((success) =>{
        if(success){
          this.$message.success("保存成功");

          //关掉自己
          this.$emit("update:visible",false);
          this.$emit("close");
        }
      }).catch((e)=>{
        console.log("失败的情况",e)
      });


    },
    getMenus(){
      getMenus().then(page=>{
        this.menus =page.data;
      })

    }
  }
}


</script>

<style scoped>




</style>
